#include "head.h"


int main(int argc, char* argv[]) 
{


    //初始化线信息结构体
    status_t status;
    init_status(&status, 4);


    //初始化线程池
    init_thread_pool(&status);

    //初始化tcp连接--即socket对象
    int socket_fd;
    //读配置文件
    init_socket(&socket_fd, "192.168.199.128", "8080");

    //初始化epoll对象，并将scoket对象加入监听
    int epoll_fd = epoll_create(1);
    add_epoll(epoll_fd, socket_fd);

    while(1){

        struct epoll_event ready_list[2];
        memset(ready_list, 0, sizeof(ready_list));

        int epoll_num = epoll_wait(epoll_fd, ready_list, 2, -1);
        if(epoll_num == -1){

        }

        for(int i = 0; i < epoll_num; i++){

            int fd = ready_list[i].data.fd;

            if(fd == socket_fd){

                int net_fd = accept(socket_fd, NULL, NULL);
                if(net_fd == -1){

                }

                //if(validate == 0){
                    pthread_mutex_lock(&status.lock);

                    enqueue(&status.q, net_fd);

                    pthread_mutex_unlock(&status.lock);
                    pthread_cond_broadcast(&status.cond);

                //}


            }
        }


    }

    return 0;
}

